package org.linkerproject.message;

import java.util.ArrayList;

import org.imlinker.plugin.say.FanfouBot;
import org.imlinker.util.StringUtils;

public class MessageList {

	public MessageList() {

	}

	private ArrayList<MessageItem> list = new ArrayList<MessageItem>();

	private FanfouBot fanfouBot = null;

	public void initFanfou(String fanfouUser, String fanfouPass) {
		if (fanfouBot == null && StringUtils.isNotEmpty(fanfouUser)
				&& StringUtils.isNotEmpty(fanfouPass)) {
			fanfouBot = new FanfouBot(fanfouUser, fanfouPass);
			fanfouBot.initial();
			ArrayList<String> messages = fanfouBot.getMessages();
			for (String m : messages) {
				list.add(new MessageItem(m, "", "fanfou"));
			}
		}
	}

	public void removeFanfou() {
		for (MessageItem item : list) {
			if (item.getKind().startsWith("fanfou")) {
				list.remove(item);
			}
		}

	}

	public String getHtml() {
		StringBuffer buffer = new StringBuffer("");

		for (MessageItem item : list) {
			buffer.append("<div>");
			buffer.append(item.getTitle() + ":" + item.getContent());
			buffer.append("</div>");
		}
		return buffer.toString();

	}

}
